(function($){
	var KEY = "jforest.rolling";

	var Rolling = function(element,options){
		this.el = element;
		this.options = $.extend({
			speed:1000,
			run:true
		},options); 
		var self = this,opts = this.options;
		var height = $(this.el).find('>ul:first-child').height()-$(this.el).height();
	    this.timer = setInterval(function(){
	    	if(opts.run == true){
	    		element.scrollTop++;
	    		if(element.scrollTop >= height){
	    			element.scrollTop = 0;
	    		}
	    	}
	    }, opts.speed);
	    this.el.onmouseover=function(){opts.run=false;}
   		this.el.onmouseout=function(){opts.run = true;}
	}

	$.fn.jfRolling = function(){
		var args = Array.prototype.slice.call(arguments, 0);
		var value = undefined;
		this.each(function () {
			var $this = $(this);
			if (args.length === 0 || typeof(args[0]) === "object") {
				opts = args.length === 0 ? {} : $.extend({}, args[0]);
				value = new Rolling(this,opts);$this.data(KEY,value); //创建控件
			}else if (typeof(args[0]) === "string"){
				var entity = $this.data(KEY);
                if(entity === undefined){return;}
                value = entity[args[0]].apply(entity, args.slice(1));
			}else{
				 throw 'Invalid arguments to '+KEY+' plugin: ' + args;
			}
	    });
	    return (value === undefined) ? this : value;
	};
	
	$.fn.jfRolling.Constructor = Rolling;
	
})(window.jQuery)